clear all;
close all;
global Z0;
R=30;
L=10*1e-9;
C=2.5*10*1e-12;
Z0=50;
f=2*1e9;
Vp=3*1e8;
ZL=R+j*(2*pi*f*L-1/(2*pi*f*C));
beta=2*pi*f./Vp;
l=0:0.0001:1;
Zin=Z0*(ZL+j*Z0*tan(beta*l))./(Z0+j*ZL*tan(beta*l));
[dif_opt,i]=min(abs(real(Zin)-Z0));
lopt=l(i);
fprintf('Optimal length:lopt=%f\n',lopt);
beta=2*pi*f./Vp;
gamma_0=(ZL-Z0)./(ZL+Z0);
SWR=(1+abs(gamma_0))./(1-abs(gamma_0));
plot(1,real(Zin),'LineWidth',2.0)
grid;
xlabel('length,m'),ylabel('Re(Zin),\Omega');
fprintf('Zin(lopt)=(%f+j(%f))Ohm,SWR=%f\n',real(Zin(i)),imag(Zin(i)),SWR);
